package com.yxy.controller.admin;

import com.yxy.common.PageResult;
import com.yxy.common.Result;
import com.yxy.constant.RequestMapperConstant;
import com.yxy.domain.dto.IncentiveDTO;
import com.yxy.domain.dto.IncentivePageQueryDTO;
import com.yxy.service.IncentiveService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(RequestMapperConstant.ADMIN_REQUEST_MAPPER + "incentive")
@Slf4j
public class IncentiveController {

    private final IncentiveService incentiveService;
    public IncentiveController(IncentiveService incentiveService) {
        this.incentiveService = incentiveService;
    }

    /**
     * 添加激励语句
     * @param incentiveDTO
     * @return
     */
    @PostMapping("/add")
    public Result<String> add(@RequestBody IncentiveDTO incentiveDTO){
        log.info("添加激励语句：{}", incentiveDTO);
        incentiveService.add(incentiveDTO);
        return Result.success("添加成功");
    }

    /**
     * 分页查询激励语句
     * @param incentivePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> page(IncentivePageQueryDTO incentivePageQueryDTO){
        log.info("分夜查询激励语句结果集：{}", incentivePageQueryDTO);
        PageResult pageResult = incentiveService.page(incentivePageQueryDTO);
        return Result.success("", pageResult);
    }

    /**
     * 修改状态
     * @return
     */
    @PutMapping("/{id}/{status}")
    public Result status(@PathVariable int id, @PathVariable int status){
        log.info("修改状态：{}, {}", id, status);
        incentiveService.state(id, status);
        return Result.success("");
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/batchDelete")
    public Result batchDelete(@RequestParam("ids") List<Integer> ids){
        log.info("根据id删除：{}", ids);
        incentiveService.batchDelete(ids);
        return Result.success("删除成功");
    }
}
